﻿using Model.Repositories;

namespace Presenter.Users
{
    public class SignInPresenter
    {
        private ISignInView _view;

        public SignInPresenter(ISignInView view)
        {
            _view = view;
            _view.EntitySignIn += ViewEntitySignIn;
        }

        public void Reload(ISignInView view)
        {
            _view = view;
            _view.EntitySignIn += ViewEntitySignIn;
        }

        void ViewEntitySignIn(string email, string password)
        {
            var obj = RepositoryManager.Instance.UserRepository.GetByEmailAndPassword(email, password);
            _view.CanSignIn = obj != null;

            if (obj != null)
                _view.SetSessionParameters(obj.Id, obj.Email, obj.Password);
        } 
    }
}

